//
//  YTOrderListViewCell.m
//  YiTuDriverClient
//
//  Created by 石少庸 on 2017/5/29.
//  Copyright © 2017年 Yitu. All rights reserved.
//

#import "YTOrderListViewCell.h"
#import "YTOrderListModel.h"
#import <YYWebImage/YYWebImage.h>

@interface YTOrderListViewCell ()
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet UIImageView *typeImage;
@property (weak, nonatomic) IBOutlet UILabel *typeDesText;
@property (weak, nonatomic) IBOutlet UILabel *timeText;
@property (weak, nonatomic) IBOutlet UILabel *airportText;
@property (weak, nonatomic) IBOutlet UILabel *destinationText;
@property (weak, nonatomic) IBOutlet UILabel *kmText;
@property (weak, nonatomic) IBOutlet UILabel *priceText;
@property (weak, nonatomic) IBOutlet UIView *readedView;
@property (weak, nonatomic) IBOutlet UIImageView *labelImage;
@property (weak, nonatomic) IBOutlet UILabel *dayText; // 非包车显示预估路程，包车显示天数
@end

@implementation YTOrderListViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    _bgView.layer.cornerRadius = 5.0;
    _bgView.layer.masksToBounds = YES;
}

- (void)setModel:(YTOrderListModel *)model {
    _model = model;
    
    // 右上角角标
    if ([model.isReward integerValue]) {
        _labelImage.image = [UIImage imageNamed:@"order_state_bouns"];
    }
    
    if ([model.orderStar integerValue] >= 4) {
        _labelImage.image = [UIImage imageNamed:@"order_state_star"];
    }
    
    _typeDesText.text = [NSString stringWithFormat:@"%@·%@·%@辆", model.subTypeName, model.carTypeName, model.carCount];
    _timeText.text = model.useTime;
    _dayText.text = @"预估路程";
    _airportText.text = model.fromAddress;
    _destinationText.text = model.toAddress;
    _kmText.text = [NSString stringWithFormat:@"%@km", model.estimatedDistance];
    _priceText.text = [NSString stringWithFormat:@"¥%@", model.driverPrice];
    if ([model.noRead isEqualToString:@"0"]) { // 已读
        _readedView.backgroundColor = [UIColor lightGrayColor];
    }
    
    // 图片
    switch (model.subType) {
        case 101:{
            _typeImage.image = [UIImage imageNamed:@"order_jieji"];
            _typeDesText.textColor = [UIColor colorWithRed:0.33 green:0.61 blue:0.73 alpha:1.00];
        }
            break;
        case 102:{
            _typeImage.image = [UIImage imageNamed:@"order_songji"];
            _typeDesText.textColor = [UIColor colorWithRed:0.35 green:0.64 blue:0.97 alpha:1.00];
        }
            break;
        case 107:
        case 108:
        case 106:
        case 103: {
            _typeImage.image = [UIImage imageNamed:@"order_baoche"];
            _typeDesText.textColor = [UIColor colorWithRed:0.90 green:0.32 blue:0.41 alpha:1.00];
            _dayText.text = @"服务天数";
            _kmText.text = [NSString stringWithFormat:@"%.1f天", [model.days floatValue]];
        }
            break;
        case 104:{
            _typeImage.image = [UIImage imageNamed:@"order_single"];
            _typeDesText.textColor = [UIColor colorWithRed:0.95 green:0.56 blue:0.21 alpha:1.00];
        }
            break;
    }
}

- (void)prepareForReuse {
    [super prepareForReuse];
    _typeImage.image = nil;
    _labelImage.image = nil;
    _typeDesText.textColor = kBlackColor;
    _typeDesText.text = nil;
    _timeText.text = nil;
    _airportText.text = nil;
    _destinationText.text = nil;
    _kmText.text = nil;
    _priceText.text = nil;
    _dayText.text = nil;
    _readedView.backgroundColor = kRedColor;
}

@end
